package com.sojson.service.impl;

import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.sojson.config.exception.TransException;
import com.sojson.dao.TransferRecordDao;
import com.sojson.entity.po.TransferRecord;
import com.sojson.enums.ETransferRecordStatus;
import com.sojson.service.TransferRecordService;

/**
 * Service实现类
 * 
 * @author liu
 * @date 2021-04-23
 */
@Service
public class TransferRecordServiceImpl implements TransferRecordService {

    @Resource
    private TransferRecordDao transferRecordDaoImpl;

    /**
     * 单条插入
     * 
     * @param transferRecord
     * @return
     * @throws SQLException 
     */
    @Override
    public int insert(TransferRecord transferRecord) {
        int insert = transferRecordDaoImpl.insert(transferRecord);
        return insert;
    }

    /**
     * 批量插入
     * 
     * @param transferRecord
     * @return
     * @throws SQLException 
     */
    @Override
    public int insertList(TransferRecord transferRecord) {
        int insertList = transferRecordDaoImpl.insertList(transferRecord.getTransferRecords());
        return insertList;
    }

    /**
     * 通过对象批量删除(物理删除)
     * 
     * @param transferRecord
     * @return
     * @throws SQLException 
     */
    @Override
    public int deleteByDto(TransferRecord transferRecord) {
        int deleteByDto = transferRecordDaoImpl.deleteByDto(transferRecord);
        return deleteByDto;
    }

    /**
     * 统计全部数量
     * 
     * @return
     * @throws SQLException 
     */
    @Override
    public int countAll() {
        int countAll = transferRecordDaoImpl.countAll();
        return countAll;
    }

    /**
     * 查询所有
     * 
     * @return
     * @throws SQLException 
     */
    @Override
    public List<TransferRecord> findAll() {
        List<TransferRecord> findAll = transferRecordDaoImpl.listAll();
        return findAll;
    }

    /**
     * 根据对象统计数量
     * 
     * @param transferRecord
     * @return
     * @throws SQLException 
     */
    @Override
    public int countByDto(TransferRecord transferRecord) {
        int countByDto = transferRecordDaoImpl.countByDto(transferRecord);
        return countByDto;
    }

    /**
     * 根据对象查询
     * 
     * @param transferRecord
     * @return
     * @throws SQLException 
     */
    @Override
    public List<TransferRecord> findByDto(TransferRecord transferRecord) {
        List<TransferRecord> findByDto = transferRecordDaoImpl.listByDto(transferRecord);
        return findByDto;
    }

    /**
     * 通过id删除(物理删除)
     * 
     * @param id
     * @return
     */
    @Override
    public int deleteById(Integer id) {
        int deleteById = transferRecordDaoImpl.deleteById(id);
        return deleteById;
    }

    /**
     * 通过id列表删除(物理删除)
     * 
     * @param ids
     * @return
     */
    @Override
    public int deleteByIdList(List<Integer> ids) {
        int deleteByIdList = transferRecordDaoImpl.deleteByIdList(ids);
        return deleteByIdList;
    }

    /**
     * 通过id更新(全部更新)
     * 
     * @param transferRecord
     * @return
     */
    @Override
    public int updateById(TransferRecord transferRecord) {
        int updateById = transferRecordDaoImpl.updateById(transferRecord);
        return updateById;
    }

    /**
     * 通过id列表更新(全部更新)(更新内容相同)
     * 
     * @param transferRecord
     * @return
     */
    @Override
    public int updateStaticByIdList(TransferRecord transferRecord) {
        int updateStaticByIdList = transferRecordDaoImpl.updateStaticByIdList(transferRecord);
        return updateStaticByIdList;
    }

    /**
     * 通过id列表更新(全部更新)(更新内容不相同)
     * 
     * @param transferRecord
     * @return
     */
    @Override
    public int updateChangeByIdList(TransferRecord transferRecord) {
        int updateChangeByIdList = transferRecordDaoImpl.updateChangeByIdList(transferRecord.getTransferRecords());
        return updateChangeByIdList;
    }

    /**
     * 通过id更新(局部更新)
     * 
     * @param transferRecord
     * @return
     */
    @Override
    public int updatePartialById(TransferRecord transferRecord) {
        int updatePartialById = transferRecordDaoImpl.updatePartialById(transferRecord);
        return updatePartialById;
    }

    /**
     * 通过id列表更新(局部更新)(更新内容相同)
     * 
     * @param transferRecord
     * @return
     */
    @Override
    public int updateStaticPartialByIdList(TransferRecord transferRecord) {
        int updateStaticPartialByIdList = transferRecordDaoImpl.updateStaticPartialByIdList(transferRecord);
        return updateStaticPartialByIdList;
    }

    /**
     * 通过id列表更新(局部更新)(更新内容不相同)
     * 
     * @param transferRecord
     * @return
     */
    @Override
    public int updateChangePartialByIdList(TransferRecord transferRecord) {
        int updateChangePartialByIdList =
            transferRecordDaoImpl.updateChangePartialByIdList(transferRecord.getTransferRecords());
        return updateChangePartialByIdList;
    }

    /**
     * 通过id查询
     * 
     * @param id
     * @return
     */
    @Override
    public TransferRecord findById(Integer id) {
        TransferRecord findById = transferRecordDaoImpl.findById(id);
        return findById;
    }

    /**
     * 通过id列表查询
     * 
     * @param ids
     * @return
     */
    @Override
    public List<TransferRecord> findByIdList(List<Integer> ids) {
        List<TransferRecord> findByIdList = transferRecordDaoImpl.findByIdList(ids);
        return findByIdList;
    }

    /**
     * 通过对象查询id列表
     * 
     * @param transferRecord
     * @return
     */
    @Override
    public List<Integer> findIdByDto(TransferRecord transferRecord) {
        List<Integer> findIdByDto = transferRecordDaoImpl.findIdByDto(transferRecord);
        return findIdByDto;
    }

    /**
     * 通过orderNo删除(物理删除)
     * 
     * @param orderNo
     * @return
     */
    @Override
    public int deleteByOrderNo(String orderNo) {
        int deleteByOrderNo = transferRecordDaoImpl.deleteByOrderNo(orderNo);
        return deleteByOrderNo;
    }

    /**
     * 通过orderNo列表删除(物理删除)
     * 
     * @param orderNos
     * @return
     */
    @Override
    public int deleteByOrderNoList(List<String> orderNos) {
        int deleteByOrderNoList = transferRecordDaoImpl.deleteByOrderNoList(orderNos);
        return deleteByOrderNoList;
    }

    /**
     * 通过orderNo更新(全部更新)
     * 
     * @param transferRecord
     * @return
     */
    @Override
    public int updateByOrderNo(TransferRecord transferRecord) {
        int updateByOrderNo = transferRecordDaoImpl.updateByOrderNo(transferRecord);
        return updateByOrderNo;
    }

    /**
     * 通过orderNo列表更新(全部更新)(更新内容相同)
     * 
     * @param transferRecord
     * @return
     */
    @Override
    public int updateStaticByOrderNoList(TransferRecord transferRecord) {
        int updateStaticByOrderNoList = transferRecordDaoImpl.updateStaticByOrderNoList(transferRecord);
        return updateStaticByOrderNoList;
    }

    /**
     * 通过orderNo列表更新(全部更新)(更新内容不相同)
     * 
     * @param transferRecord
     * @return
     */
    @Override
    public int updateChangeByOrderNoList(TransferRecord transferRecord) {
        int updateChangeByOrderNoList =
            transferRecordDaoImpl.updateChangeByOrderNoList(transferRecord.getTransferRecords());
        return updateChangeByOrderNoList;
    }

    /**
     * 通过orderNo更新(局部更新)
     * 
     * @param transferRecord
     * @return
     */
    @Override
    public int updatePartialByOrderNo(TransferRecord transferRecord) {
        int updatePartialByOrderNo = transferRecordDaoImpl.updatePartialByOrderNo(transferRecord);
        return updatePartialByOrderNo;
    }

    /**
     * 通过orderNo列表更新(局部更新)(更新内容相同)
     * 
     * @param transferRecord
     * @return
     */
    @Override
    public int updateStaticPartialByOrderNoList(TransferRecord transferRecord) {
        int updateStaticPartialByOrderNoList = transferRecordDaoImpl.updateStaticPartialByOrderNoList(transferRecord);
        return updateStaticPartialByOrderNoList;
    }

    /**
     * 通过orderNo列表更新(局部更新)(更新内容不相同)
     * 
     * @param transferRecords
     * @return
     */
    @Override
    public int updateChangePartialByOrderNoList(TransferRecord transferRecord) {
        int updateChangePartialByOrderNoList =
            transferRecordDaoImpl.updateChangePartialByOrderNoList(transferRecord.getTransferRecords());
        return updateChangePartialByOrderNoList;
    }

    /**
     * 通过orderNo查询
     * 
     * @param orderNo
     * @return
     */
    @Override
    public TransferRecord findByOrderNo(String orderNo) {
        TransferRecord findByOrderNo = transferRecordDaoImpl.findByOrderNo(orderNo);
        return findByOrderNo;
    }

    /**
     * 通过orderNo列表查询
     * 
     * @param orderNos
     * @return
     */
    @Override
    public List<TransferRecord> findByOrderNoList(List<String> orderNos) {
        List<TransferRecord> findByOrderNoList = transferRecordDaoImpl.findByOrderNoList(orderNos);
        return findByOrderNoList;
    }

    /**
     * 通过对象查询orderNo列表
     * 
     * @param transferRecord
     * @return
     */
    @Override
    public List<String> findOrderNoByDto(TransferRecord transferRecord) {
        List<String> findOrderNoByDto = transferRecordDaoImpl.findOrderNoByDto(transferRecord);
        return findOrderNoByDto;
    }

    /**
     * 通过对象删除(逻辑删除)
     * 
     * @param transferRecord
     * @return
     */
    @Override
    public int deleteByDtoAndUpdate(TransferRecord transferRecord) {
        int deleteByDtoAndUpdate = transferRecordDaoImpl.deleteByDtoAndUpdate(transferRecord);
        return deleteByDtoAndUpdate;
    }

    /**
     * 统计所有未删除的数据
     * 
     * @return
     */
    @Override
    public int countAllAndStatusNo() {
        int countAllAndStatusNo = transferRecordDaoImpl.countAllAndStatusNo();
        return countAllAndStatusNo;
    }

    /**
     * 查询所有未删除的数据
     * 
     * @return
     */
    @Override
    public List<TransferRecord> findAllAndStatusNo() {
        List<TransferRecord> findAllAndStatusNo = transferRecordDaoImpl.findAllAndStatusNo();
        return findAllAndStatusNo;
    }

    /**
     * 通过id删除(逻辑删除)
     * 
     * @param id
     * @return
     */
    @Override
    public int deleteByIdAndUpdate(Integer id) {
        TransferRecord findById = transferRecordDaoImpl.findById(id);
        if (findById.getStatus() != ETransferRecordStatus.SECCUSS.getCode()) {
            throw new TransException("提现未完成,如果删除,佣金无法退还");
        }
        int deleteByIdAndUpdate = transferRecordDaoImpl.deleteByIdAndUpdate(id);
        return deleteByIdAndUpdate;
    }

    /**
     * 通过id列表删除(逻辑删除)
     * 
     * @param ids
     * @return
     */
    @Override
    public int deleteByIdListAndUpdate(List<Integer> ids) {
        int deleteByIdListAndUpdate = transferRecordDaoImpl.deleteByIdListAndUpdate(ids);
        return deleteByIdListAndUpdate;
    }

    /**
     * 通过orderNo删除(逻辑删除)
     * 
     * @param orderNo
     * @return
     */
    @Override
    public int deleteByOrderNoAndUpdate(String orderNo) {
        int deleteByOrderNoAndUpdate = transferRecordDaoImpl.deleteByOrderNoAndUpdate(orderNo);
        return deleteByOrderNoAndUpdate;
    }

    /**
     * 通过orderNo列表删除(逻辑删除)
     * 
     * @param orderNos
     * @return
     */
    @Override
    public int deleteByOrderNoListAndUpdate(List<String> orderNos) {
        int deleteByOrderNoListAndUpdate = transferRecordDaoImpl.deleteByOrderNoListAndUpdate(orderNos);
        return deleteByOrderNoListAndUpdate;
    }

    /**
     * 清空数据(物理清空)
     */
    @Override
    public void clear() {
        transferRecordDaoImpl.clear();
    }

    /**
     * 清空数据(逻辑清空)
     */
    @Override
    public void clearAndUpdate() {
        transferRecordDaoImpl.clearAndUpdate();
    }

}